package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.Tariff;

public class TariffDao extends SuperDao {

	/**
	 * 查询资费表(查有效的)
	 */
	public List<Object> watchAllTariff() {
		String hql = "from Tariff where status = 0";
		return super.find(hql);
	}

	/**
	 * 通过id查询资费表(查有效的)
	 */
	public List<Object> watchTariffById(Long tariffId) {
		/*
		 * String hql = "from Tariff where tariffId = " + tariffId +
		 * " and status = 0"; return super.find(hql);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Tariff where tariffId = ");
		sb.append(tariffId);
		sb.append(" and status = 0");

		return super.find(sb.toString());
	}

	public Tariff FindById(long tariffid) {
		return (Tariff) this.getHibernateTemplate().get(Tariff.class, tariffid);
	}

	public List<Object> getList(Tariff tariff, int index) {
		StringBuilder sb = new StringBuilder();
		sb.append("From Tariff");
		return super.findPage(index, sb.toString());
	}

	public int getCount() {
		String hql = "Select Count(*) From Tariff";

		List<Object> list = find(hql);
		Long s = (Long) list.get(0);
		return s.intValue();
	}

	/**
	 * 保存资费
	 * 
	 * @return
	 */

	public boolean save(Tariff tariff) {
		this.getHibernateTemplate().save(tariff);
		return true;
	}

	/**
	 * 通过GoodsId查询资费信息 * @param GoodsId
	 */
	public Object getTariffByGoodsId(Long GoodsId) {
		String sql = "from Tariff where goods_id = ?";
		List<Object> list = getObject(sql, new Object[] { GoodsId });
		if (list.isEmpty()) {
			return null;
		}

		return list.get(0);
	}

	public boolean Delete(Tariff tariff) {
		this.getHibernateTemplate().delete(tariff);
		return true;
	}

}
